package com.meixun.xuanke.user.dao;

import com.meixun.xuanke.user.model.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;
import java.util.List;

public interface UserDao {
    /**
     *
     * @return
     */
    @Select("SELECT ui.UserID userId,p.tel userName,ui.Pwd pass,s.SchoolID schoolId, p.onOff onOff,s.UserID stuUserId ,4 type FROM userinfo ui LEft JOIN parent p on  p.userID=ui.UserID LEft JOIN student s on s.UserID=p.stuUserID WHERE p.tel is not null and p.tel !='';")
    List<User> getUserListAll();
    /**
     *
     * @param schoolId
     * @return
     */
    @Select("SELECT ui.UserID userId,p.tel userName,ui.Pwd pass,s.SchoolID schoolId, p.onOff onOff,s.UserID stuUserId ,4 type FROM userinfo ui LEft JOIN parent p on  p.userID=ui.UserID LEft JOIN student s on s.UserID=p.stuUserID WHERE p.tel is not null and p.tel !='' and p.schoolID=#{arg0};")
    List<User> getUserListBySchool(@Param("arg0") String schoolId);

    /**
     *
     * @param userID
     * @return
     */
    @Select("SELECT ui.UserID userId,p.tel userName,ui.Pwd pass,s.SchoolID schoolId, p.onOff onOff,s.UserID stuUserId ,4 type FROM userinfo ui LEft JOIN parent p on  p.userID=ui.UserID LEft JOIN student s on s.UserID=p.stuUserID WHERE p.tel is not null and p.tel !='' and ui.UserID=#{arg0};")
    List<User> getUserListByUserId(@Param("arg0") String userID);

    /**
     *
     * @param userName
     * @param pass
     * @return
     */
    @Select("SELECT ui.UserID userId,p.tel userName,ui.Pwd pass,s.SchoolID schoolId, p.onOff onOff,s.UserID stuUserId ,4 type FROM userinfo ui LEft JOIN parent p on  p.userID=ui.UserID LEft JOIN student s on s.UserID=p.stuUserID WHERE p.tel is not null and p.tel =#{arg0} and ui.Pwd=#{arg1};")
    List<User> getUserListByLogin(@Param("arg0") String userName, @Param("arg1") String pass);


    /**
     * 查询学生userIdid
     * @param userId
     * @return
     */
    @Select("SELECT p.stuUserID userId FROM parent p WHERE p.userID=#{arg0} OR p.stuUserID =#{arg0} LIMIT 0,1;")
    HashMap<String,Object> querystuUserId(@Param("arg0") String userId);

    /**
     * 查询学生年级
     * @param userId
     * @return
     */
    @Select("select left(sc.Grade,4) Grade,sc.ClassTypeID from student s LEFT JOIN schoolclass sc ON sc.SchoolClassID=s.SchoolClassID WHERE s.UserID=#{arg0};")
    HashMap<String,Object> queryGrade(@Param("arg0") String userId);




}
